<!DOCTYPE html>
<html >
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>面向对象</title>
</head>
<body>
    
</body>
<script>
    // 创建对象1.构造函数
    let zs = new Object();
    console.log( 'zs',zs);
    // 通过构造函数，为同一类对象添加相同属性和方法
    function Member(username,password){
        this.username =username;
        this.password =password;  
       this.sayHello = function() {
            console.log("你好");
            
        } 
    }
    let lisi = new Member();
    console.log('lisi',lisi);
    
    // 创建对象2.字面量
    let ww = {};
    console.log('ww',ww);
    
    // 动态的伪对象添加属性和方法
    ww.username = "wangwu";
    ww.password = '123456';
    ww.sayHello = () => {
        console.log("你好");
        
    };
    console.log('ww',ww);
    
    let wc = new Member('旺财','123213');
    let lf = new Member('来福','988764');
    console.log('旺财',wc);
    console.log('来福',lf);


    

    // 访问对象属性的两种方式
    // .操作符
    console.log(lf.username);
    // []操作符
    console.log(lf['username']);

    // 动态的打印不同属性
    function showName(person,attr){
        console.log(person [attr]);
        
    }
    showName(lf, 'username');
    showName(lf, 'password');

    // 调用对象的两种方法
   lf.sayHello();
   lf['sayHello']();

   
    
    
    
    
    







</script>
</html>